﻿using JWT;
using JWT.Algorithms;
using JWT.Serializers;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using XxSystem.FileManager.core;

namespace XxSystem.FileManager.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        [HttpPost("login")]
        public IActionResult Login([FromBody] UserLoginRequest request)
        {
            if (request == null) throw new ArgumentNullException(nameof(request));
            if (request.UserName == "admin" && request.Password == "123qwf") 
            { 
                var dic = new Dictionary<string, string>();
                dic.Add("uid", request.UserName);
                var r = JWTHelper.GetJwtToken(dic);
                return Ok(r);
            }
            return Unauthorized();
        }
    }
}
